/**
 * Created by Administrator on 2018/1/8.
 */
function submit()
{
    var name = document.getElementById("username").value;
    if(name.length<3|| name.length>15)
    {
        alert("用户名长度须在3-15之间!");
        return;
    }

    var userPass = $("#password").val();
    if(userPass.length<6 || userPass.length >15)
    {
        alert("密码长度须在6-15之间!");
        return;
    }

    var userRPass = $("#Repassword").val();
    if (userPass != userRPass){
        alert("两次密码输入不一致!");
        return;
    }

    var flag = 0;
    //检验是否重名
    $.ajax({
        type: "POST",
        url: "/user/selectUsername.do",
        data: {"username":name},
        async: false,
        success: function(date) {
            console.log(date);
            if (date.status == 1) {
            alert(date.msg);
                flag =  1;
        }
        },
        error: function(date) {
            alert("服务器繁忙!");
        }
    });

    if(flag == 1) {
        return;
    }


    $.ajax({
        type: "POST",
        url: "/user/register.do",
        data: {"username":name,"password":userPass},
        async: false,
        success: function(date) {
            console.log(date);
            if (date.status == 0) {
                window.location.href = "login.jsp";
            }
        },
        error: function(date) {
            alert("服务器繁忙!");
        }
    });

}